package com.ley.springboot.commons.utils;

import java.util.UUID;

/**
 * UUID utility class
 *
 * @author 2036185346@qq.com
 **/
public class UUIDUtils {

    /**
     * random UUID and has no UUID delimiter <b>-</b>
     **/
    public static String randomUUID() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * random length UUID and when length > UUID.length,the length=UUID.length
     *
     * @param length the generate uuid length
     **/
    public static String randomUUID(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("length need >0");
        } else {
            String uuid = UUIDUtils.randomUUID();
            if (length > uuid.length()) {
                length = uuid.length();
            }
            return uuid.substring(0, length);
        }
    }

}
